<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //call  func1.call(func2)就是将func2代替func1的this，来实现fucn1的方法
        //apply就是，就是第二个值是数组而已
        function func(name){
           
            this.name=name;
        }
        console.log(new func("唐玮"));

        //call
        let urls={url:"tw.com"};
        func.call(urls,"唐玮学习js");//后面的值不用跟数组

        console.log(urls);
        func.apply(urls,["唐玮学习js"])//后面的值必须是数组
        console.log(urls);



        //bind ,和call差别很小 就在方法后面加上   ()就行
        //如果在bind里面先传入参数的话，那就执行bind括号里面的。
        //如果bind里面没有传值的话，那就执行外面括号的值，
        //再者，如果bind里面缺少值的话，那就在外边的括号赋值上对应的值
        //  总之，前面的括号优先执行，后面的后执行
        // function show(name){
        //     console.log(this.name);
        // }

        // show.bind({name:"唐玮"})();//唐玮

        function show(a,b){
              return this.f+a+b;
        }
console.log( show.call({f:1},1,1)); //3
console.log(show.apply({f:1},[1,1]));//3  
console.log(show.bind({f:1},1,1)());//3

console.log(show.bind({f:1})(1,1));//3

console.log(show.bind({f:1},1)(1));//3


    </script>
</body>
</html>